<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="账号">
        <el-input v-model="info.account" disabled placeholder="请输入登录账号" />
      </el-form-item>

      <el-form-item label="昵称">
        <el-input v-model="info.username" disabled placeholder="昵称" />
      </el-form-item>
      <el-form-item label="当前余额">
        <el-input v-model="info.credit" type="number" disabled />
      </el-form-item>
      <el-form-item label="充值金额" prop="money" required>
        <el-input v-model="form.money" type="number" placeholder="充值金额" />
      </el-form-item>
      <el-form-item label="备注" prop="remark" required>
        <el-input v-model="form.remark" type="textarea" rows="3" placeholder="充值备注" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="$router.push({path:'/user/index'})">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import api from '@/api/member'

export default {
  components: {},
  data() {
    return {
      info: {
        account: '',
        username: ''
      },
      form: {
        user_id: 0,
        remark: '',
        credit: '0.00',
        money: 0
      }
    }
  },

  mounted() {
    if (this.$route.query.hasOwnProperty('user_code')) {
      this.getData(this.$route.query.user_code)
    }
  },

  methods: {

    getData(user_code) {
      api.info({ user_code: user_code }).then((res) => {
        this.info = res.data
        this.form.user_id = res.data.user_id
      })
    },

    onSubmit() {
      if (this.form.money <= 0 && !this.form.remark) {
        return this.$message.error('请输入充值金额和备注')
      }
      this.$confirm('确定提交吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.recharge({
          user_id: this.form.user_id,
          money: this.form.money,
          remark: this.form.remark
        }).then((res) => {
          this.$message({
            type: 'success',
            message: res.msg,
            duration: 500,
            onClose: () => {
              this.$router.push({ path: 'index' })
            }
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    }
  }
}
</script>

<style scoped>
.line {
  text-align: center;
}

.editor-content {
  margin-top: 20px;
}

.article-textarea ::v-deep {

textarea {
  padding-right: 40px;
  resize: none;
  border: none;
  border-radius: 0px;
  border-bottom: 1px solid #bfcbd9;
}

}
</style>

